﻿
Partial Class WebForm_ManageEnlistRecord_SearchEnlistRecord
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.ObjectDataSource1.SelectParameters("CreateBy").DefaultValue = Page.User.Identity.Name
    End Sub

    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "btnCancel" Then
            If Me.UpdateAllStatus() = True Then
                Me.gv.DataBind()
            End If
        End If
    End Sub

    Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim hideStatus As HiddenField = TryCast(e.Row.FindControl("hideStatus"), HiddenField)
            Dim chk As CheckBox = TryCast(e.Row.FindControl("chk"), CheckBox)

            'If hideStatus.Value <> "WA" Then
            If DataBinder.Eval(e.Row.DataItem, "CourseCount") > 0 Then
                chk.Visible = False
            End If
        End If
    End Sub

    Public Event Cancel(ByVal sender As Object, ByVal e As System.EventArgs)

    Protected Sub gv_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gv.RowUpdated
        RaiseEvent Cancel(Me, New EventArgs)
    End Sub

    Protected Sub chkAll_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim chkAll As CheckBox = TryCast(sender, CheckBox)

        For Each row As GridViewRow In Me.gv.Rows
            Dim chk As CheckBox = TryCast(row.FindControl("chk"), CheckBox)

            chk.Checked = chkAll.Checked
        Next

    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.ObjectDataSource1.SelectParameters("TrainingWHour").DefaultValue = Me.txtTrainingBHour.Text.Replace("'", "''")
        Me.gv.DataBind()
    End Sub
End Class

Partial Class WebForm_ManageEnlistRecord_SearchEnlistRecord
    
    Private Function UpdateAllStatus() As Boolean
        Dim dao As New BLL_SearchEnlistRecord

        Using scope As New Transactions.TransactionScope
            For Each row As GridViewRow In Me.gv.Rows
                Dim chk As CheckBox = TryCast(row.FindControl("chk"), CheckBox)
                Dim key As DataKey = Me.gv.DataKeys(row.RowIndex)

                If chk.Checked = True Then
                    dao.BLL_Update(key("ApplicationID"))
                End If
            Next

            scope.Complete()

            Return True

        End Using
    End Function
End Class

